package com.huzz.controller;

import cn.dev33.satoken.annotation.SaCheckSafe;
import com.huzz.entity.SysSecondAuth;
import com.huzz.service.ISysSecondAuthService;
import com.huzz.util.body.JsonResult;
import com.huzz.util.body.ResultTool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Name 名称
 * @Description 描述
 * @Author 童年的纸飞机
 * @Since 2023-04-2023/4/27 09:00
 */
@Api(tags = "系统二级认证模块 API")
@RestController
@RequestMapping("/api/second-auth")
public class SysSecondAuthController {

    @Autowired
    private ISysSecondAuthService secondAuthService;

    // TODO 上线之后删除
    @SaCheckSafe(value = "second_auth_manager")
    @ApiOperation(value = "新建二级认证")
    @PostMapping("/createSecondAuth")
    public JsonResult<String> createSecondAuth(@RequestParam(value = "业务模块标识") String service,
                                               @RequestParam(value = "二级认证密码") String secondPassword,
                                               @RequestParam(value = "描述") String description,
                                               @RequestParam(value = "认证过期时长(秒)", defaultValue = "120") Integer safeTime) {
        return ResultTool.response(secondAuthService.createSecondAuth(service, secondPassword, description, safeTime));
    }

    @ApiOperation(value = "二级认证列表")
    @GetMapping("/findSecondAuthList")
    public JsonResult<List<SysSecondAuth>> findSecondAuthList() {
        return ResultTool.success(secondAuthService.findSecondAuthList());
    }

    @SaCheckSafe(value = "second_auth_manager")
    @ApiOperation(value = "编辑二级认证")
    @PutMapping("/updateSecondAuthById")
    public JsonResult<String> updateSecondAuthById(@RequestParam(value = "ID") Integer id,
                                                   @RequestParam(value = "二级认证密码") String secondPassword,
                                                   @RequestParam(value = "描述") String description,
                                                   @RequestParam(value = "认证过期时长(秒)") Integer safeTime) {
        return ResultTool.response(secondAuthService.updateSecondAuthById(id, secondPassword, description, safeTime));
    }
}
